package dsl.common.domain;

import java.util.ArrayList;

/**
 * 变量列表，变量表示见{@link dsl.common.domain.Variable}
 */
public class VariableList extends ArrayList<Variable> {
    /**
     * 根据变量名在变量表中查找相应变量的值
     * 
     * @param name 变量名
     * @return 返回相应变量的值，未找到返回空值
     */
    public String getValueByName(String name) {
        for (int i = 0; i < this.size(); i++)
            if (this.get(i).name.equals(name))
                return this.get(i).value;
        return null;
    }

    /**
     * 根据变量名在变量表中查找相应变量
     * 
     * @param name 变量名
     * @return 返回相应变量，未找到返回空值
     */
    public Variable findByName(String name) {
        for (int i = 0; i < this.size(); i++)
            if (this.get(i).name.equals(name))
                return this.get(i);
        return null;
    }

    @Override
    public String toString() {
        String str = "VariableList:\n";
        for (int i = 0; i < this.size(); i++)
            str = str + "\t" + this.get(i).toString() + "\n";
        return str;
    }
}
